import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
/**
 * 带确认框的文本按钮
 * @author: ljq
 * @since: 2019-01-10 18:22:27
 */
import * as React from 'react';
import { Modal, Popconfirm } from 'antd';
import AuthCheck from '../auth-check';

var ConfirmBtn = function (_React$Component) {
    _inherits(ConfirmBtn, _React$Component);

    function ConfirmBtn() {
        _classCallCheck(this, ConfirmBtn);

        var _this = _possibleConstructorReturn(this, (ConfirmBtn.__proto__ || Object.getPrototypeOf(ConfirmBtn)).apply(this, arguments));

        _this.state = {
            visible: false
        };
        _this.handleConfirm = function () {
            var onConfirm = _this.props.onConfirm;

            onConfirm && onConfirm();
            _this.setState({ visible: false });
        };
        _this.getPopBtn = function () {
            var _this$props = _this.props,
                msg = _this$props.msg,
                style = _this$props.style,
                children = _this$props.children;

            return React.createElement(
                Popconfirm,
                { title: msg, onConfirm: _this.handleConfirm, style: { minWidth: 300 } },
                React.createElement(
                    'a',
                    { style: style },
                    children
                )
            );
        };
        _this.getModalBtn = function () {
            var visible = _this.state.visible;
            var _this$props2 = _this.props,
                msg = _this$props2.msg,
                style = _this$props2.style,
                children = _this$props2.children;

            return React.createElement(
                React.Fragment,
                null,
                React.createElement(
                    Modal,
                    { title: '\u786E\u8BA4\u64CD\u4F5C', visible: visible, onOk: _this.handleConfirm, onCancel: function onCancel() {
                            return _this.setState({ visible: false });
                        } },
                    React.createElement(
                        'p',
                        null,
                        msg
                    )
                ),
                React.createElement(
                    'a',
                    { style: style, onClick: function onClick() {
                            return _this.setState({ visible: true });
                        } },
                    children
                )
            );
        };
        _this.renderBtn = function () {
            var type = _this.props.type;

            if (type === 'modal') {
                return _this.getModalBtn();
            }
            return _this.getPopBtn();
        };
        return _this;
    }

    _createClass(ConfirmBtn, [{
        key: 'render',
        value: function render() {
            var check = this.props.check;

            return React.createElement(
                AuthCheck,
                { check: check },
                this.renderBtn()
            );
        }
    }]);

    return ConfirmBtn;
}(React.Component);

export default ConfirmBtn;